<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<!-- Casting SPELs in Lisp - Emacs Lisp Edition, a Comic Book
     Written by Conrad Barski, M.D., http://lisperati.com
     Edited by James A. Webb, http://uberkode.com -->

<head>

  <title>Casting SPELs in Lisp (16)</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="author" content="James A. Webb" />
  <meta name="date" content="2007-09-16T00:00:00+00:00" />
  <meta name="keywords" content="Emacs, Lisp" />

</head>

<body>

<center>

<table cellspacing="10" width="500">
  <tr>
    <td>
      Another problem with our <tt>describe-location</tt> function is 
      that it doesn't tells us about the paths in and out of the 
      location to other locations. Let's write a function that 
      describes these paths:
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkblue">
  (defun describe-path (path)
    `(there is a ,(second path) going ,(first path) from here -))
</pre>
    </td>
  </tr>
  <tr>
    <td>
      Ok, now this function looks pretty strange: It almost looks 
      more like a piece of data than a function. Let's try it out 
      first and figure out <i>how</i> it does what it does later:
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkblue">
  (describe-path '(west door garden))
</pre>
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkgreen">
  ==> (there is a door going west from here -)
</pre>
    </td>
  </tr>
  <tr>
    <td>
      So now it's clear: This function takes a list describing a 
      path (just like we have inside our <tt>map</tt> variable) and 
      makes a nice sentence out of it. Now when we look at the 
      function again, we can see that the function "looks" a lot 
      like the data it produces: It basically just splices the first
      and second item from the path into a declared sentence. How does
      it do this? It uses <b><i>back-quoting</i></b>!
    </td>
  </tr>
  <tr>
    <td>
      Remember that we've used a quote before to <i>flip</i> the 
      interpreter from <i>Code</i> mode to <i>Data</i> mode. Well, 
      by using the back-quote (the quote in the upper left corner of 
      the keyboard) we can not only <i>flip</i>, but then also 
      <i>flop</i> back into <i>Code</i> mode by using a comma:
    </td>
  </tr>
  <tr>
    <td align="center">
      <img src="../images/back-quote.jpg"
        width="500" 
        height="103" 
        alt="The flip-flopping back-quote" />
    </td>
  </tr>
  <tr>
    <td align="center">
      &lt;&lt; <a href="casting-spels-emacs-1.html">begin</a>
      &lt; <a href="casting-spels-emacs-15.html">previous</a> - 
      <a href="casting-spels-emacs-17.html">next</a> &gt;
      <a href="casting-spels-emacs-35.html" >end</a> &gt;&gt;
    </td>
  </tr>
</table>

</center>

</body>

</html>